package com.jc.service;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jc.common.util.Base64Util;
import com.jc.common.util.HttpUtil;
import com.jc.common.util.MD5;

public class RequestAppGame {

	public static void main(String[] args) {
		
		try {
			
//			queryGame();
			queryGame2();
//			queryGame();
		}catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	
	
	
	public static void queryGame() throws Exception  {
		
		//{"amount":10000,"orderId":"201904151802487529304","state":1,"userId":753564}
		
		
		
		String url = "http://39.98.66.218:81/api/game/optscore";
		String orderId = "201904151802487529304";
		Long amount = 10000L;
		Long userId = 753564L;
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("userId", userId);
		map.put("orderId", "201904151802487529304");
		map.put("amount", amount);
		map.put("state", 1);
		
		String jsonStr = JSONObject.toJSONString(map);
		String data = Base64Util.encode(jsonStr);
		String after = "data=" + data + "&key=5359fd245e3fe71c0dee8ed8788f0b9d";
		System.out.println("签名MD5加密前: " + after);
		
		String sign = MD5.passmd5(after);

		System.out.println("签名MD5加密后: " + sign);
		Map<String,Object> parMap = new HashMap<String,Object>();
		parMap.put("data", data);
		parMap.put("sign", sign);
		System.out.println("请求参数 : " + JSONObject.toJSON(parMap));
		//===========================================
		String str1 = HttpUtil.post(url, parMap);
		System.out.println("返回报文 : " + str1);
		
		
		System.out.println( "=================>  "  + Base64Util.decode(data) );
		
		
		
	}
	
	
	
	public static void queryGame2() throws Exception  {
		
		//{"data":"eyJhbW91bnQiOjYwMCwib3JkZXJJZCI6IjExMTIyMjIyMjIyMiIsInN0YXRlIjoxLCJ1c2VySWQiOjc4NTY2OH0=","sign":"aa274f333c39d0ce5467976eea2fe107"}
		
		
		String url = "http://39.98.66.218:81/api/game/optscore";
		String data = "eyJ1c2VySWQiOiA4MzgwLCJvcmRlcklkIjoieHh4eHh4eHh4eHh4IiwiYW1vdW50IjogMTB9";
		String sign = "8263db0ea27bf894cefab81c6bcfba38";
		
		Map<String,Object> parMap = new HashMap<String,Object>();
		String bter = Base64Util.decode(data);
		System.out.println("========: " + bter);
		
		
		String after = "data=" + data + "&key=5359fd245e3fe71c0dee8ed8788f0b9d";
		System.out.println("签名MD5加密前: " + after);
		
		String ddds = MD5.passmd5(after);
		System.out.println("签名MD5加密后: " + ddds);


		//{"data":"eyJhbW91bnQiOjEwMDAwLCJvcmRlcklkIjoiMjAxOTA0MTUxODAyNDg3NTI5MzA0Iiwic3RhdGUiOjEsInVzZXJJZCI6NzUzNTY0fQ==","sign":"3131bbbe0d4b3d39971ee0c95966534b"}
		
		
		data = "eyJhbW91bnQiOjEwMDAwLCJvcmRlcklkIjoiMjAxOTA0MTUxODI3MzMyNDc0MzI4Iiwic3RhdGUiOjEsInVzZXJJZCI6NzUzNTY0fQ==";
		ddds = "8b9b6824c5df508fb81f70f0f1069f65";
		
		
		
		parMap.put("data", data);
		parMap.put("sign", ddds);
		
		
		String pst = HttpUtil.post(url, parMap);
		
		System.out.println( "=================>  "  + Base64Util.decode(data) );
		
		System.out.println("返回报文 : " + pst);
	}
	
	

}
